﻿using MediatR;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.AddressW
{
    public class CountySeachHandler : IRequestHandler<CountySeachCommon, Result>
    {
        public readonly IBaseRepository<County> CountyRepository;

        public CountySeachHandler(IBaseRepository<County> countyRepository)
        {
            CountyRepository = countyRepository;
        }

        public async Task<Result> Handle(CountySeachCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var list = CountyRepository.GetAll().Where(x=>x.CityId==request.CityId).ToList();
                res.Code = (int)CommonEnumCode.success;
                res.Data = list;
                res.Msg = "县列表";
            }
            catch (Exception ex)
            {

            }
            return res;
        }
    }
}
